<!-- 辅助器具适配列表 -->
<template>
  <el-card>
    <el-row>
      <el-form ref="form" :model="searchDto" inline label-suffix=":">
        <el-form-item label="关键字" prop="keywords">
          <el-input
            v-model="searchDto.keywords"
            placeholder="器具设配标题"
            style="width:250px"
          ></el-input>
        </el-form-item>
        <el-form-item label="创建时间" label-width="90px">
          <el-date-picker
            v-model="date"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy年MM月dd日"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="primary" @click="search">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-s-open" type="primary" @click="clear">重置</el-button>
        </el-form-item>
        <el-form-item class="clear_item-margin-bottom">
          <el-button type="primary" icon="el-icon-plus" @click="add">新增基本康复</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <page-table
      ref="adaptation"
      :page-data="pageData"
      :loading="loading"
      :do-get-page-data="getPageData"
    >
      <el-table-column type="index" label="编号" width="80" align="center" />
      <el-table-column prop="assistActivityTitle" label="基本康复标题" align="center" />
      <el-table-column prop="assistActivityDesc" label="康复活动说明" align="center" show-overflow-tooltip />
      <el-table-column prop="startTime" label="开始时间" align="center" />
      <el-table-column prop="endTime" label="结束时间" align="center" />
      <el-table-column prop="createTime" label="创建时间" align="center" />
      <el-table-column prop="publishStatus" label="状态" align="center" width="100">
        <template slot-scope="scope">
          <sz-badge :value="statusMap[scope.row.publishStatus]" :type="statusStyle(scope.row)" />
        </template>
      </el-table-column>
      <el-table-column prop="status" label="活动进度" align="center" width="120">
        <template slot-scope="scope">
          <sz-badge :value="activitiesStatus[scope.row.status]" :type="statusStyle(scope.row)" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="250" fixed="right">
        <template slot-scope="scope">
          <el-tooltip content="发布" v-if="scope.row.publishStatus!==1" placement="top">
            <el-button
              type="button"
              size="mini"
              icon="el-icon-s-promotion"
              @click="releaseActivity(scope.row,1)"
            >
            </el-button>
          </el-tooltip>
          <el-tooltip content="编辑" v-if="scope.row.publishStatus!==1" placement="top">
            <el-button
              type="button"
              size="mini"
              icon="el-icon-edit"
              @click="editActivity(scope.row)"
            >
            </el-button>
          </el-tooltip>
          <el-tooltip content="详情" placement="top">
            <el-button
              type="button"
              size="mini"
              icon="el-icon-view"
              @click="viewActivity(scope.row)"
            >
            </el-button>
          </el-tooltip>
          <el-tooltip
            content="下架"
            v-if="scope.row.publishStatus===1 && scope.row.status < 2"
            placement="top"
          >
            <el-button
              type="button"
              size="mini"
              icon="el-icon-warning-outline"
              @click="releaseActivity(scope.row,2)"
            >
            </el-button>
          </el-tooltip>
          <el-tooltip content="删除" v-if="scope.row.publishStatus!==1" placement="top">
            <el-button
              type="button"
              size="mini"
              icon="el-icon-delete"
              @click="delActivity(scope.row)"
            >
            </el-button>
          </el-tooltip>
        </template>
      </el-table-column>
    </page-table>
  </el-card>
</template>
<script>
export default {
  name: "Adaptation",
  data() {
    return {
      statusMap: { 0: '保存', 1: '发布', 2: '下架' },
      activitiesStatus: {
        0: "活动未开始",
        1: "活动进行中",
        2: "机构鉴定中",
        3: "待上传财政资料",
        4: "备货中",
        5: "活动完结"
      },
      searchDto: {
        keywords: null,
        pageIndex: 1,
        pageSize: 10
      },
      date: [],
      pageData: {},
      loading: false
    }
  },
  methods: {
    statusStyle(row) {
      switch (row.publishStatus) {
        case 0:
          return "success";
        case 1:
          return "warning";
        case 2:
          return "danger";
      }
      switch (row.status) {
        case 0:
          return "danger";
        case 1:
          return "success";
        case 2:
          return "warning";
        case 3:
          return "warning";
        case 4:
          return "warning";
        case 5:
          return "success";
      }
    },
    getPageData(val) {
      let tem = Object.assign(this.searchDto, val);
      if (this.date) {
        tem.startTime = this.date[0];
        tem.endTime = this.date[1];
      }
      this.API.getAssistActivityInfoPageList(tem).then(ret => {
        this.pageData = ret.data;
      });
    },
    search() {
      this.getPageData();
    },
    clear() {
      this.$refs.form.resetFields()
      this.date = []
      this.getPageData();
    },
    add() {
      this.$router.push({ name: 'addOrEditAdaptation' })
    },

    // 发布/下架
    releaseActivity({ id: activityId }, type) {
      this.$confirm(`确认${type === 1 ? '发布' : '下架'}此基本康复活动?`, "提示", { type: "warning" }).then(() => {
        this.API.publishAssistActivityInfo({ activityId, status: type }).then(ret => {
          this.success("操作成功!");
          this.getPageData();
        });
      }).catch(() => {
      })
    },

    editActivity({ id }) {
      this.$router.push({ name: 'addOrEditAdaptation', query: { id } })
    },

    viewActivity({ id }) {
      this.$router.push({ name: 'adaptationInfo', query: { id } })
    },

    // 删除辅助器具适配
    delActivity({ id }) {
      this.$confirm("确认删除此基本康复活动?", "提示", { type: "warning" }).then(() => {
        this.API.deleteAssistActivityInfoById({ id }).then(ret => {
          this.success("删除成功!");
          this.getPageData();
        });
      }).catch(() => {
      });
    },
  },
  mounted() {
    this.getPageData();
  }
}
</script>
<style scoped lang="scss"></style>
